<template>
  <a-card  class="info" title="员工调岗调薪表">
    <!-- table区域-begin -->
    <div v-if="dataSource.length != 0">
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <span slot="notify" slot-scope="text, record">
          <a-icon title="催办提醒" v-if="record.taskUrge" theme="twoTone" twoToneColor="#eb2f96"
                  @click="taskNotifyMe(flowCode,record.id)" type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
        </span>

      </a-table>
    </div>
    <div v-else>暂无调岗调薪信息</div>
    <erp-hr-post-salary-adjustment-modal ref="modalForm" @ok="modalFormOk"></erp-hr-post-salary-adjustment-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import {JeecgBpmListMixin} from '@/mixins/JeecgBpmListMixin'
  import ErpHrPostSalaryAdjustmentModal from '@/views/erp/hr/adjust/modules/ErpHrPostSalaryAdjustmentModal'
  import { getAction } from '@/api/manage'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'ErpHrPostSalaryAdjustmentList',
    mixins:[JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpHrPostSalaryAdjustmentModal,
    },
    data () {
      return {
        description: '员工调岗调薪申请表管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'申请人',
            align:"center",
            dataIndex: 'employeeId',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['employeeId'], text + '')
              }
            }
          },
          {
            title:'人员编号',
            align:"center",
            dataIndex: 'employeeNo',
          },
          // {
          //   title:'所在单位',
          //   align:"center",
          //   dataIndex: 'workUnit',
          //   customRender: (text) => {
          //     if (!text) {
          //       return ''
          //     } else {
          //       return filterMultiDictText(this.dictOptions['workUnit'], text + '')
          //     }
          //   }
          // },
          // {
          //   title:'所在部门',
          //   align:"center",
          //   dataIndex: 'departmentId',
          //   customRender: (text) => {
          //     if (!text) {
          //       return ''
          //     } else {
          //       return filterMultiDictText(this.dictOptions['departmentId'], text + '')
          //     }
          //   }
          // },
          // {
          //   title:'所属团队',
          //   align:"center",
          //   dataIndex: 'teamId',
          //   customRender: (text) => {
          //     if (!text) {
          //       return ''
          //     } else {
          //       return filterMultiDictText(this.dictOptions['teamId'], text + '')
          //     }
          //   }
          // },
          {
            title:'岗位名称',
            align:"center",
            dataIndex: 'positionId',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['positionId'], text + '')
              }
            }
          },
          {
            title:'调整前薪级',
            align:"center",
            dataIndex: 'beforeSalaryScale',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['beforeSalaryScale'], text + '')
              }
            }
          },
          {
            title:'调整前薪资',
            align:"center",
            dataIndex: 'beforeSalary',
          },
          {
            title:'生效日期',
            align:"center",
            dataIndex: 'effectiveDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'调整后薪级',
            align:"center",
            dataIndex: 'afterSalaryScale',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['afterSalaryScale'], text + '')
              }
            }
          },
          {
            title:'调整后薪资',
            align:"center",
            dataIndex: 'afterSalary',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/hr/adjust/erpHrPostSalaryAdjustment/queryAdjustByEmployeeId",
          delete: "/api/erp/hr/adjust/erpHrPostSalaryAdjustment/delete",
          deleteBatch: "/api/erp/hr/adjust/erpHrPostSalaryAdjustment/deleteBatch",
          exportXlsUrl: "/api/erp/hr/adjust/erpHrPostSalaryAdjustment/exportXls",
          importExcelUrl: "api/erp/hr/adjust/erpHrPostSalaryAdjustment/importExcel",
          bizCount: "/api/erp/hr/adjust/erpHrPostSalaryAdjustment/bizCount",
        },
        dictOptions:{},
        superFieldList:[],
        disableMixinCreated: true
      }
    },
    created() {
      this.getSuperFieldList();
    },
    props: {
      employeeId: String
    },
    watch: {
      employeeId: {
        handler: function(val){
          this.initDictConfig(val)
        },
        immediate: true
      },
      // BUG4233 查看多人员工档案信息，信息数据被覆盖
      $route(to, from) {
        this.initDictConfig(to.query.id)
      },
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleDetail: function (record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '详情';
        this.$refs.modalForm.disableSubmit = true;
      },
      initDictConfig(id){
        initDictOptions('sys_position,name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'positionId', res.result)
          }
        })
        // initDictOptions('sys_depart,depart_name,id').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'workUnit', res.result)
        //     this.$set(this.dictOptions, 'departmentId', res.result)
        //   }
        // })
        // initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'teamId', res.result)
        //   }
        // })
        initDictOptions('erp_employee_file,name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'employeeId', res.result)
          }
        })
        initDictOptions('erp_pay_grade,salary_grade,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'beforeSalaryScale', res.result)
            this.$set(this.dictOptions, 'afterSalaryScale', res.result)
          }
        })
        this.initColumns()
        getAction(this.url.list, { employeeId: id }).then(res => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'sel_user',value:'employeeId',text:'申请人'})
        fieldList.push({type:'string',value:'employeeNo',text:'人员编号',dictCode:''})
        fieldList.push({type:'sel_depart',value:'workUnit',text:'所在单位'})
        fieldList.push({type:'sel_depart',value:'departmentId',text:'所在部门'})
        fieldList.push({type:'string',value:'teamId',text:'所属团队',dictCode:''})
        fieldList.push({type:'string',value:'positionId',text:'岗位名称',dictCode:''})
        fieldList.push({type:'string',value:'beforeSalaryScale',text:'调整前薪级',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'beforeSalary',text:'调整前薪资',dictCode:''})
        fieldList.push({type:'date',value:'effectiveDate',text:'生效日期'})
        fieldList.push({type:'string',value:'afterSalaryScale',text:'调整后薪级',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'afterSalary',text:'调整后薪资',dictCode:''})
        fieldList.push({type:'string',value:'adjustRemark',text:'调整原因',dictCode:''})
        fieldList.push({type:'string',value:'adjustUnit',text:'调入单位',dictCode:''})
        fieldList.push({type:'string',value:'adjustDepart',text:'调入部门',dictCode:''})
        fieldList.push({type:'string',value:'adjustTeam',text:'调入团队',dictCode:''})
        fieldList.push({type:'string',value:'adjustPosition',text:'调入岗位',dictCode:''})
        fieldList.push({type:'sel_depart',value:'providentFundUnit',text:'公积金单位'})
        fieldList.push({type:'sel_depart',value:'insuredUnit',text:'参保单位'})
        fieldList.push({type:'string',value:'insuredBase',text:'参保基数（元）',dictCode:''})
        fieldList.push({type:'string',value:'providentFundBase',text:'公积金基数（元）',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'Text',value:'attachment',text:'附件',dictCode:''})
        fieldList.push({type:'int',value:'checkStatua',text:'审核状态',dictCode:''})
        fieldList.push({type:'string',value:'bpmStatus',text:'流程状态',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
